package com.isljj.web_chat2.controller;

import com.isljj.web_chat2.utils.CookieUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


public class Test {

    private static String parseMaxAge(String cookieString) {
        // 假设 cookieString 是类似 "name=value; Max-Age=3600; ..." 的字符串
        String[] parts = cookieString.split("; "); // 使用 "; " 作为分隔符来分割各个属性

        // 遍历所有属性来查找 token
        for (String part : parts) {
            if (part.startsWith("token=")) {
                // 提取 token 的值
                String token = part.substring("token=".length());
                //System.out.println("token : " + token);
                return token; // 找到后退出循环
            }
        }

        // 如果没有找到 Token，则输出相应信息
        System.out.println("Token: Not Specified");
        return "";
    }

    public static void main(String[] args) {
        CookieUtils cookieUtils1 = new CookieUtils();
        //Map<String,String> stringMap = cookieUtils1.parseCookieString("JSESSIONID=8B8D2056A061A5ECA21D2FEF096B8017;token=eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6IuW8oOS4iSIsInVzZXJJZCI6MSwiZXhwIjoxNzE1NTAzOTA2fQ.dMgQOsAZfpr6lQiAyUajQHJVEM204A0X7RIY6_KsifU;");
//        System.out.println(stringMap.get("JSESSIONID"));
//        System.out.println(stringMap.get("token"));
//        System.out.println(stringMap.toString());

        String cookie = "JSESSIONID=3F663CEC9FB3E5A32A86F41AE" +
                "0209F36; token=eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZS" +
                "I6IuW8oOS4iSIsInVzZXJJZCI6MSwiZXhwIjoxNzE1NTA1OTU3fQ.hlMh6jqQsK3FI0J9XJUwAZQR3uLkH8hO3lU7LmbKsh";
         String token = parseMaxAge(cookie);
        System.out.println(token);


//        String s = "1;1";

//        cookie.replace(";"," ");
//        String s2  =s.replace(';','1');
//        System.out.println(cookie);
//        System.out.println(s2);
    }
}
